﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NWN.GDY.Service.Entity;
using Sdo.Payment.Common;
using NWN.GDY.Service.Common;

namespace NWN.GDY.Service.Core.HandcardCreator
{
    public class SingleCreator : AbstractHDCreator
    {
        AbstractHDCreator hdcreator;
        string description = "单张";  
        public override string GetDescription()
        {
            if (hdcreator != null)
                return hdcreator.GetDescription() + "_" + description;
            return description;
        }

        public SingleCreator(AbstractHDCreator creator)
        {
            this.hdcreator = creator;
        }
        public SingleCreator()
        {
        }

        public override void CreateHandCard(List<Card> cards, List<Card> AllCards, List<HandCard> handcards)
        {
            if (hdcreator != null)
            {
                hdcreator.CreateHandCard(cards, AllCards, handcards);
            }
            if(cards.Count!=1)
                return;
            if (cards[0].CardType == (int)CardType.club || cards[0].CardType == (int)CardType.diamond || cards[0].CardType == (int)CardType.hearts || cards[0].CardType == (int)CardType.spade)
            {
                //Log.Lw("一张" + cards[0].SimpleName);
                handcards.Add(new HandCard() { Cards = cards, Type = HandCardType.Single });
            }
        }

        public override int CompareHandCard(HandCard lasthc, HandCard currenthc)
        {
            if (hdcreator != null)
            {
                if (hdcreator.CompareHandCard(lasthc, currenthc) == GDYConsts.ReturnDefine.SUCCESS)
                    return GDYConsts.ReturnDefine.SUCCESS;
            }
            if (lasthc.Type != HandCardType.Single || currenthc.Type != HandCardType.Single)
                return GDYConsts.ReturnDefine.HANDCARDTYPEERROR;
            if (lasthc.Cards[0].CardNum == 2)
                return GDYConsts.ReturnDefine.HANDCARDCOMPAREWRONG;
            if (currenthc.Cards[0].CardNum == 2)
                return GDYConsts.ReturnDefine.SUCCESS;
            if(lasthc.Cards[0].CardNum+1==currenthc.Cards[0].CardNum)
                return GDYConsts.ReturnDefine.SUCCESS;
            return GDYConsts.ReturnDefine.HANDCARDCOMPAREWRONG;
        }
    }
}
